/**
 * 接受组件通知触发mutation调用间接状态的方法的对象
 */
import {ADD_TODO, DELETE_TODO,
  SELECT_ALL, DELETE_COMPLETE,RECEIVE_TODOS} from "./mutation_type";
import storageUtils from "../util/storageUtils";
export default {
  addTodo({commit}, newTodo) {
    // 提交一个mutation请求  这里向mutation传递时要是一个对象
    commit(ADD_TODO, {newTodo})
  },
  deleteTodo({commit}, index) {
    commit(DELETE_TODO, {index})
  },
  selectAllTodos({commit}, check) {
    commit(SELECT_ALL, {check})
  },
  deleteCompletedTodos({commit}) {
    commit(DELETE_COMPLETE)
  },
  reqTodos({commit}) {
    setTimeout(() => {
      //读取数据
      const  todos = storageUtils.getTodos()
      commit(RECEIVE_TODOS,{todos})
    }, 500)
  }
}
